package com.loong.musicdemo.ui.mine.recent;

import android.content.Context;

import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.loong.musicdemo.R;
import com.loong.musicdemo.ui.mine.recent.fragment.RecentAlbumFragment;
import com.loong.musicdemo.ui.mine.recent.fragment.RecentMvFragment;
import com.loong.musicdemo.ui.mine.recent.fragment.RecentSongFragment;

import java.util.List;

/**
 * A [FragmentPagerAdapter] that returns a fragment corresponding to
 * one of the sections/tabs/pages.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {

    @StringRes
    private static final int[] TITLES = new int[]{R.string.recent_tab1, R.string.recent_tab2,R.string.recent_tab3,R.string.recent_tab4};
    private final Context mContext;

    public SectionsPagerAdapter(Context context, FragmentManager fm) {
        super(fm);
        this.mContext = context;
    }

    @Override
    public Fragment getItem(int position) {
        // getItem is called to instantiate the fragment for the given page.
        // Return a PlaceholderFragment (defined as a static inner class below).
        switch (position){
            case 0:
                return new RecentSongFragment();
            case 1:
                return new RecentMvFragment();
            case 3:
                return new RecentAlbumFragment();
            default:
                return new RecentSongFragment();
        }

    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mContext.getResources().getString(TITLES[position]);
    }

    @Override
    public int getCount() {
        return 4;
    }
}